package co.yixiang.modules.shop.service.impl;

import co.yixiang.modules.shop.entity.YxSalesCommissionDetail;
import co.yixiang.modules.shop.mapper.YxSalesCommissionDetailMapper;
import co.yixiang.modules.shop.mapping.CommissionDetailMap;
import co.yixiang.modules.shop.service.YxSalesCommissionDetailService;
import co.yixiang.modules.shop.web.param.YxSalesCommissionDetailQueryParam;
import co.yixiang.modules.shop.web.vo.YxSalesCommissionDetailQueryVo;
import co.yixiang.common.service.impl.BaseServiceImpl;
import co.yixiang.common.web.vo.Paging;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.io.Serializable;
import java.util.List;


/**
 * <p>
 * 业务员提成明细表 服务实现类
 * </p>
 *
 * @author hisen
 * @since 2020-06-18
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class YxSalesCommissionDetailServiceImpl extends BaseServiceImpl<YxSalesCommissionDetailMapper, YxSalesCommissionDetail> implements YxSalesCommissionDetailService {

    @Autowired
    private YxSalesCommissionDetailMapper yxSalesCommissionDetailMapper;
    @Autowired
    private CommissionDetailMap commissionDetailMap;

    @Override
    public List<YxSalesCommissionDetailQueryVo> userCommission(int uid,YxSalesCommissionDetailQueryParam yxSalesCommissionDetailQueryParam, List<Integer> saleId){
        QueryWrapper<YxSalesCommissionDetail> wrapper = new QueryWrapper<>();

        if(saleId != null && uid >0){
            wrapper.in("sales_man_id",saleId);
        }
        else if(uid > 0 &&  saleId == null) wrapper.eq("sales_man_id",uid);


        wrapper.ge("invest_time",yxSalesCommissionDetailQueryParam.getBeginDate());
        wrapper.le("invest_time",yxSalesCommissionDetailQueryParam.getEndDate());

        List<YxSalesCommissionDetailQueryVo> list = commissionDetailMap.toDto(yxSalesCommissionDetailMapper.selectList(wrapper));
        return list;
    }

}
